package com.wxxymaker.model.dao;

import com.blade.ioc.annotation.Bean;
import com.wxxymaker.model.entity.Admin;
import io.github.biezhi.anima.Anima;

/**
 * @Author: Soft
 * @Date: 2018/6/8 14:40
 * @Desc: 管理员dao层
 */
@Bean
public class AdminDao implements BaseDao<Admin> {

    @Override
    public Admin add(Admin entity) {
        Integer id = (entity).save().asInt();
        entity.setId(id);
        return (Admin) entity;
    }

    @Override
    public Admin delete(int id) {
        Admin admin = Anima.select().from(Admin.class).byId(id);
        if (admin.delete() > 0) {
            return admin;
        }
        return null;
    }

    @Override
    public int change(Admin entity) {
        return (entity).update();
    }

    @Override
    public Admin findOne(int id) {
        return Anima.select().from(Admin.class).byId(id);
    }

    public Admin findByUsername(String username) {
        return Anima.select().from(Admin.class).where(Admin::getName, username).one();
    }
}
